package com.example.sunmiv1.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.DepositDetailInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DepositDetailAdapter extends BaseAdapter {

    private Context context;
    private List<DepositDetailInfo.DataBean> list;
    private ViewHolder viewHolder;
    private int type;

    public DepositDetailAdapter(Context context, List<DepositDetailInfo.DataBean> list, int type) {
        this.context = context;
        this.list = list;
        this.type = type;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.deposit_detail_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        DepositDetailInfo.DataBean dataBean = list.get(position);
        if (type == 1) {
            viewHolder.depositDetailName.setText(dataBean.getGoods_name());
            viewHolder.depositDetailCode.setText(dataBean.getGoods_code());
            viewHolder.depositDetailFreightNumber.setText(dataBean.getGoods_number());
            viewHolder.depositDetailSkuNum.setText(dataBean.getSku_num() + "");
            viewHolder.depositDetailNum.setText(dataBean.getStock_num() + "");
            viewHolder.depositDetailPrice.setText(dataBean.getStock_price() + "");
            viewHolder.depositDetailTotal.setText(dataBean.getSubtotal() + "");
        } else {
            viewHolder.depositDetailName.setText(dataBean.getGoods_name());
            viewHolder.depositDetailCode.setText(dataBean.getGoods_code());
            viewHolder.depositDetailFreightNumber.setText(dataBean.getGoods_number());
            viewHolder.depositDetailSkuNum.setText(dataBean.getSku_num() + "");
            viewHolder.depositDetailNumMsg.setText(R.string.StorageQuantity);
            viewHolder.depositDetailNum.setText(dataBean.getStock_num() + "");
            viewHolder.depositDetailPriceMsg.setText(R.string.WarehousingPrice);
            viewHolder.depositDetailPrice.setText(dataBean.getStock_price() + "");
            viewHolder.depositDetailTotal.setText(dataBean.getSubtotal() + "");
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.depositDetail_name)
        TextView depositDetailName;
        @BindView(R.id.depositDetail_code)
        TextView depositDetailCode;
        @BindView(R.id.depositDetail_freightNumber)
        TextView depositDetailFreightNumber;
        @BindView(R.id.depositDetail_skuNum)
        TextView depositDetailSkuNum;
        @BindView(R.id.depositDetail_numMsg)
        TextView depositDetailNumMsg;
        @BindView(R.id.depositDetail_num)
        TextView depositDetailNum;
        @BindView(R.id.depositDetail_priceMsg)
        TextView depositDetailPriceMsg;
        @BindView(R.id.depositDetail_price)
        TextView depositDetailPrice;
        @BindView(R.id.depositDetail_total)
        TextView depositDetailTotal;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
